<template>
  <div>
      <el-row>
          <el-col :span="24" align="right">
              <div style="margin-top:10px">
                <el-button @click="addNewRecord" type="primary">添加监控信息</el-button>
                <el-input style="width:200px" v-model="filters.schoolName" placeholder="请输入学校名称"></el-input>
                <el-button type="primary" icon="search" @click="getSchoolVideoInfo">搜索</el-button>
                <el-button type="primary" @click="flushAll">刷新</el-button>
              </div>
              <el-row style="margin-top:20px">
                  <el-col :span="$store.getters.user.userRole=='超级管理员'?3:0">
                      <treeComponent style="margin-top:-52px" @GetNodeValue="GetNodeValue"></treeComponent>
                  </el-col>
                  <el-col :span="$store.getters.user.userRole=='超级管理员'?21:24">
                      <el-table :data="list" border>
                          <el-table-column v-for="(v,k,i) in props" :key="i" :label="labels[i]" align="center">
                              <template scope="scope">
                                  <span  v-if="k!=='url'||k!='longitude'||k!=='latitude'" >
                                      {{scope.row[k]}}
                                  </span>
                              </template>
                          </el-table-column>
                          <el-table-column label="操作" align="center">
                              <template scope="scope">
                                  <el-button type="text" @click="ckDetail(scope.row.videoID)">查看详情</el-button>
                                  <el-button type="text" @click="editSchoolVideo(scope.row.videoID)">编辑</el-button>
                                  <el-button type="text" @click="deleteSchoolVideo(scope.row.videoID)">删除</el-button>
                              </template>
                          </el-table-column>
                      </el-table>
                  </el-col>
                  <el-col :span="24" style="margin-top:10px" align="right">
                      <el-pagination layout="prev, pager, next" :total="totalInfo" @current-change="handleCurrentChange">
                      </el-pagination>
                  </el-col>
              </el-row>
          </el-col>
      </el-row>
      <el-dialog title="校园详细信息" :visible.sync="visible">
           <div id="table">
         <table class="userInfoEditTable" style="border-collapse:collapse;background-color:white;" width="100%" cellspacing="0">
            <tr v-for="(v,k,i) in form" :key="v">
                <td class="tb_label">{{labels2[i]}}</td>
                <td>
                    {{v}}
                </td>
            </tr>
            <tr>
              <td colspan="2" align="center">
                <el-button type="text" size="large" @click="printTable('table')">[打印]</el-button>
                <el-button type="text" size="large" @click="visible=false">[关闭]</el-button>
              </td>
          </tr>
        </table>
        </div>
      </el-dialog>
  </div>
</template>

<script>
import treeComponent from "../../components/common/treeComponent";
import * as api from "@/api/schoolManage";
export default {
  components: {
    treeComponent: treeComponent
  },
  data() {
    return {
      visible:false,
      SchoolVideoType:[],
      form:{

      },
      filters: {
        schoolName:'',
        page: 1,
        pageSize: 10
      },
      list: [
       {
        videoID:'',// bigint(20) NOT NULL AUTO_INCREMENT,
        videoName:'',// varchar(100) DEFAULT NULL,
        longitude:'',// double(32,8) DEFAULT NULL COMMENT '经度',
        latitude:'',// double(32,8) DEFAULT NULL COMMENT '纬度',
        videoURL:'',// varchar(200) DEFAULT NULL COMMENT '视频流地址URL表示',
        schoolName:'',// bigint(20) DEFAULT NULL COMMENT '所属学校',
        producter:'',// varchar(200) DEFAULT NULL COMMENT '生产厂家',
        remarks:'',// varchar(200) DEFAULT NULL COMMENT '备注',
        netGridName:''
       }
      ],
      totalInfo: 0,
      props: {
        videoName:'',// varchar(100) DEFAULT NULL,
        longitude:'',// double(32,8) DEFAULT NULL COMMENT '经度',
        latitude:'',// double(32,8) DEFAULT NULL COMMENT '纬度',
        schoolName:'',// bigint(20) DEFAULT NULL COMMENT '所属学校',
        producter:'',// varchar(200) DEFAULT NULL COMMENT '生产厂家',
        netGridName:''// 所属网格
      },
      labels: ['监控名称','经度','纬度','所属学校','生产厂家','所属网格'],
      labels2: ['编号','监控名称','经度坐标','纬度坐标','监控地址URL','所属学校','生产厂家','备注','所属网格'],
    };
  },
  methods: {
    deleteSchoolVideo(id) {
      this.$confirm("是否删除此校园信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
          api.deleteSchoolVideo(id).then(res => {
            if (res.data) {
              this.$message({
                type: "success",
                message: "删除成功!"
              });
              this.getSchoolVideoInfo()
            } else {
              this.$message({
                type: "error",
                message: res.message
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    flushAll() {
      this.filters.schoolName = this.filters.netGridID = null;
      this.getSchoolVideoInfo();
    },
    handleCurrentChange(val) {
      this.filters.page = val;
      this.getSchoolVideoInfo();
    },
    ckDetail(id) {
      this.visible = true
      api.getSchoolVideoDetail(id).then(res=>{
          this.form = res.data
      })
    },
    addNewRecord() {
      this.$router.push("add");
    },
    GetNodeValue(val) {
      this.filters.netGridID = val;
      this.getSchoolVideoInfo();
    },
    editSchoolVideo(id) {
      this.$router.push({ path: "edit", query: { id: id } });
    },
    getSchoolVideoInfo() {
      api.getSchoolVideoQuery(this.filters).then(res => {
        this.list = res.data.vos;
        this.totalInfo = res.data.page.totalCount;
      });
    this.filters.schoolName = this.filters.netGridID = null;
    }
  },
  mounted() {
    this.getSchoolVideoInfo();
  }
};
</script>


<style scoped>
.userInfoEditTable,
.userInfoEditTable td {
  border: 1px solid darkgrey;
  padding: 10px;
}

.tb_label {
  width: 20%;
  text-align: right;
}
</style>
